package cn.scantd.core.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;

import cn.scantd.core.attrs.Scope;
import cn.scantd.core.util.EnumUtil;
import cn.scantd.kit.StrKit;

public class JavaMethod implements Serializable {

    private static final long serialVersionUID = -2127808246091240717L;
    
    private String name;
    private String fullName;
    private List<JavaMethodParam> params = new ArrayList<JavaMethodParam>();
    private boolean isConstructor;
    private String returnClazz;
    private boolean isStatic;
    private boolean isFinal;
    private Scope scope;
    private JavaDoc javaDoc;
    
    @SuppressWarnings("unchecked")
    public JavaMethod(MethodDeclaration methodDeclaration) {
        name = StrKit.trim(methodDeclaration.getName().getIdentifier());
        fullName = StrKit.trim(methodDeclaration.getName().getFullyQualifiedName());
        List<SingleVariableDeclaration> parameters = methodDeclaration.parameters();
        for (SingleVariableDeclaration singleVariableDeclaration : parameters) {
            params.add(new JavaMethodParam(singleVariableDeclaration));
        }
        if (methodDeclaration.isConstructor()) {
            isConstructor = true;
        } else {
            isConstructor = false;
            returnClazz = StrKit.trim(methodDeclaration.getReturnType2().resolveBinding().getQualifiedName());
        }
        isStatic = methodDeclaration.modifiers().contains(Modifier.STATIC);
        isFinal = methodDeclaration.modifiers().contains(Modifier.FINAL);
        scope = EnumUtil.getScope(methodDeclaration.getModifiers());
        javaDoc = new JavaDoc(methodDeclaration.getJavadoc());
    }
    
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getFullName() {
        return fullName;
    }
    public void setFullName(String fullName) {
        this.fullName = fullName;
    }
    public List<JavaMethodParam> getParams() {
        return params;
    }
    public void setParams(List<JavaMethodParam> params) {
        this.params = params;
    }
    public boolean isConstructor() {
        return isConstructor;
    }
    public void setConstructor(boolean isConstructor) {
        this.isConstructor = isConstructor;
    }
    public String getReturnClazz() {
        return returnClazz;
    }
    public void setReturnClazz(String returnClazz) {
        this.returnClazz = returnClazz;
    }
    public boolean isStatic() {
        return isStatic;
    }
    public void setStatic(boolean isStatic) {
        this.isStatic = isStatic;
    }
    public boolean isFinal() {
        return isFinal;
    }
    public void setFinal(boolean isFinal) {
        this.isFinal = isFinal;
    }
    public Scope getScope() {
        return scope;
    }
    public void setScope(Scope scope) {
        this.scope = scope;
    }
    public JavaDoc getJavaDoc() {
        return javaDoc;
    }
    public void setJavaDoc(JavaDoc javaDoc) {
        this.javaDoc = javaDoc;
    }
    
}
